#ifndef RANDOMTHREAD_H
#define RANDOMTHREAD_H

#include <QObject>
#include <QThread>
#include <QRunnable>

class RandomThread :public QThread
{
    Q_OBJECT
public:
    explicit RandomThread(QThread * parent = nullptr);
    void run() override;

signals:
    /* 自定义信号 */
    void Generate(const std::vector<int> & nums);

public slots:

};

class SortThread :public QThread
{
    Q_OBJECT
public:
    explicit SortThread(QThread * parent = nullptr);

    void SetNums(std::vector<int> & nums)
    {
        this->nums = nums;
    }

    void run() override;

signals:
    /* 自定义信号 */
    void SortFinished(const std::vector<int> & nums);

public slots:

private:
    std::vector<int> nums;

};

class ThreadObj : public QObject
{
    Q_OBJECT
public:
    explicit ThreadObj(QObject * parent = nullptr):QObject(parent){}
    void Generate();
    void Sort();
    void SetNums(std::vector<int> & nums)
    {
        this->nums = nums;
    }
signals:
    /* 自定义信号 */
    void GenerateFinished(const std::vector<int> & nums);
    void SortFinished(const std::vector<int> & nums);
private:
    std::vector<int> nums;
};

// 得在QT object继承系统内
// 继承Object


/* 线程池任务QRunnable */
// 要继承object，因为runnable没有父类用不了信号和槽
class RandomRunnable:  public QObject,public QRunnable
{
    Q_OBJECT
public:
    RandomRunnable()
    {
        setAutoDelete(true);
    }
    void run() override;
signals:
    void GenerateFinished(const std::vector<int> & nums);

};

class SortRunnable:  public QObject,public QRunnable
{
    Q_OBJECT
public:
    SortRunnable()
    {
        setAutoDelete(true);
    }

     void run() override;
     void SetNums(std::vector<int> & nums)
     {
         this->nums = nums;
     }
signals:
    void SortFinished(const std::vector<int> & nums);

private:
    std::vector<int> nums;

};


#endif // RANDOMTHREAD_H
